import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

public class HW_8_isMax {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入数组行数：");
        int hang=sc.nextInt();
        System.out.println("请输入数组列数：");
        int lie=sc.nextInt();
        int[][] shuzu=createShuzu(hang,lie);
        printShuzu(shuzu);
        for(int i=0;i<shuzu.length;i++){
            for(int j=0;j<shuzu[i].length;j++){
                if(isHangMax(shuzu,i,j)&&isLieMax(shuzu,i,j)){
                    System.out.println(shuzu[i][j]+"是"+(i+1)+"行"+(j+1)+"列最大的值");
                }
            }
        }
    }
    //生成二维数组
    public static int[][] createShuzu(int x,int y){
        Random r = new Random();
        int[][] shuzu = new int[x][y];
        for (int i = 0; i < x; i++) {
            for (int j = 0; j < y; j++) {
                shuzu[i][j] = r.nextInt(101);
            }
        }
        return shuzu;
    }
    //打印二维数组
    public static void printShuzu(int[][] shuzu){
        for (int i = 0; i < shuzu.length; i++) {
            for (int j = 0; j < shuzu[i].length; j++) {
                System.out.print(shuzu[i][j] + " ");
            }
            System.out.println();
        }
    }
    //判断是否该行最大数
    public static boolean isHangMax(int[][] shuzu,int x,int y) {
        for (int i = 0; i < shuzu[x].length; i++) {
            if (shuzu[x][i] > shuzu[x][y]) {
                return false;
            }
        }
        return true;
    }
    //判断是否该列最大数
    public static boolean isLieMax(int[][] shuzu,int x,int y) {
        for (int i = 0; i < shuzu.length; i++) {
            if (shuzu[i][y] > shuzu[x][y]) {
                return false;
            }
        }
        return true;
    }
}
